<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Db;
/**
 * 首页接口
 */
class Index extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * 首页
     *
     */
    public function index()
    {
        $this->success('请求成功');
    }
    public function zf()
    {
//        $username = $this->request->request('username');
        $yxid = $this->request->request('yxid');
        $token = $this->request->request('token');
        if($token!='9ffed97b'){
            $this->error(__('token不正确'));
        }
//        halt($username);
//        jid
        $jidlogdel=db::table('fa_jdklog')
            ->where('jid',$yxid)
//            ->where('username',$username)
            ->field('id,dkks,zfip')
            ->select();

        $this->success('请求成功',$jidlogdel);
    }
    public function dk()
    {
        $username = $this->request->request('username');
        $yxid = $this->request->request('yxid');
        $token = $this->request->request('token');
        if($token!='af2820a44'){
            $this->error(__('token不正确'));
        }
//        jid
        $jidlogdel=db::table('fa_jdklog')
            ->where('jid',$yxid)
//            ->where('username',$username)
            ->field('id,dkks')
            ->select();
        $this->success('请求成功',$jidlogdel);
    }

//转发的ip和端口
    public function ipdk()
    {
//        $username = $this->request->request('username');
//        $yxid = $this->request->request('yxid');
//        $token = $this->request->request('token');
//        if($token!='af2820a44'){
//            $this->error(__('token不正确'));
//        }
//        jid
        $jidlogdel=db::table('fa_jd')
            ->field('id,ip,dk')

            ->select();
        $this->success('请求成功',$jidlogdel);
    }


//加一个获取节点配置api
    public function getjd()
    {
//        $username = $this->request->request('username');
       $ip= self::getClientIP();
//       halt($ip);

//        $jidlogdel=db::table('fa_jd')
//            ->field('id,ip,dk,jddk')
//            ->where('ip',$ip)
//            ->select();
//        halt($jidlogdel);
        $jidlogdelcunm=Db::table('fa_jd')
            ->where('ip',$ip)
            ->field('id,ip,dk,jddk')
            ->find();
        if (!$jidlogdelcunm){
            $this->error('ip数据空');
        }
        $this->success('请求成功',$jidlogdelcunm);
//        $this->success('请求成功',$jidlogdel);
    }
    //获取ip
    function getClientIP(){
        //getenv()函数定义：取得系统的环境变量
        if (getenv("HTTP_CLIENT_IP")) {
            $ip = getenv("HTTP_CLIENT_IP");
        } elseif (getenv("HTTP_X_FORWARDED_FOR")) {
            $ip = getenv("HTTP_X_FORWARDED_FOR");
        } elseif (getenv("REMOTE_ADDR")) {
            $ip = getenv("REMOTE_ADDR");
        } else {
            $ip = "Unknow";
        }
        if ($ip == '::1'){
            //本地
            $ip = '127.0.0.1';
        }
        return $ip;
    }
//上线的
    function nodeonline(){

        $ip=self::getClientIP();
//        $ip='113.128.135.61';
        $node=DB::table('fa_jd')->where('ip',$ip)->find();
        $id=0;
//        halt($node['id']);
        if ($node){
            DB::table('fa_jd')->where('id',$node['id'])->update([
                'zxtime'   => date('Y-m-d H:i:s'),
            ]);



            $id = DB::table('ss_node_infolog')->insertGetId(
                ['log_time' => time(), 'node_id' => $node['id'], 'ip' => $node['ip'],'logtime'=>date('Y-m-d H:i:s')]
            );
        }

        $this->success('请求成功',$id);

    }








}
